<?php

namespace App\Http\Resources;


use Illuminate\Http\Resources\Json\ResourceCollection;

class UserCollection extends ResourceCollection
{
    public function toArray($request)
    {
        return [
            'list'=>$this->collection->transform(function ($item) {
                return [
                    'id' => $item->id,
                    'username' => $item->username,
                    'nickname' => $item->nickname,
                    'mobile' => $item->mobile,
                    'genderLabel' => $item->gender,
                    'avatar' => $item->avatar,
                    'email' => $item->email,
                    'deptName' => optional($item->dept)->name,
                    'roleNames' => $item->email,
                    'status' => $item->status,
                    'createTime' => $item->create_time ,
                    'updateTime' => $item->update_time
                ];
            }),
            'total' => $this->total(), //数据总数
        ];
    }
}

